package edu.uhcl.team_drone.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.math.Vector3;
import edu.uhcl.team_drone.drone.Drone;
import edu.uhcl.team_drone.game.ProjectGame;
import static edu.uhcl.team_drone.game.ProjectGame.cam;
import static edu.uhcl.team_drone.game.ProjectGame.modelBatch;
import edu.uhcl.team_drone.world.GameWorld;

public class PlayScreen implements Screen {

    private GameWorld world;
    private Drone drone;    
    private ProjectGame game;
    
    public PlayScreen(ProjectGame gameIn){
        this.game = gameIn;
    }

    @Override
    public void show() {

        drone = new Drone(new Vector3(100, 100, 100));
        Gdx.input.setInputProcessor(drone.inputCmp);
        world = new GameWorld();
        updateCameraFromDrone();
    }

    @Override
    public void render(float delta) {
        // clears the screen every frame. You get dragging graphics if you dont
        Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

        // update player/cam
        drone.update(Gdx.graphics.getDeltaTime());

        updateCameraFromDrone();

        cam.update(true);

        // render
        if (world != null) {
            world.render(cam, Gdx.graphics.getDeltaTime());
        }
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void hide() {
    }

    @Override
    public void dispose() {
        // throw away heavy objects
        modelBatch.dispose();
        world.dispose();
    }

    private void updateCameraFromDrone() {
        cam.position.set(drone.movementCmp.getPosition());
        cam.direction.set(drone.movementCmp.getDirection());
        cam.up.set(drone.movementCmp.getUp());
    }

}
